package com.gongpingjialoan.utility;

import android.text.TextUtils;

import com.gongpingjialoan.activity.car.CarListFragment;
import com.gongpingjialoan.bean.AgentRecommand;
import com.gongpingjialoan.bean.SpecificBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/10/28.
 */
public class GetAgentGroupData {


    public static List<AgentGroupData> getAgentData(AgentRecommand agentRecommand ,Map<String, SpecificBean> mSpecificBeanMap ,  String type) {
        List<AgentGroupData> agentGroupDatas = new ArrayList<>();
        if (agentRecommand.getData() != null) {
            SpecificBean specificBean = null;
            specificBean = mSpecificBeanMap.get(type);

            //精确
            if (specificBean != null) {
                if (specificBean.getBrand_model_zhs() != null && specificBean.getBrand_model_zhs().size() > 0) {
                    AgentGroupData agentGroupData = new AgentGroupData("车型:", getString(specificBean.getBrand_model_zhs()));
                    agentGroupDatas.add(agentGroupData);
                }
                if (!TextUtils.isEmpty(specificBean.getPrice())) {
                    AgentGroupData agentGroupData = new AgentGroupData("购车预算:", specificBean.getPrice() + "万");
                    agentGroupDatas.add(agentGroupData);
                }
                if (!TextUtils.isEmpty(specificBean.getCity())) {
                    AgentGroupData agentGroupData = new AgentGroupData("城市:", specificBean.getCity());
                    agentGroupDatas.add(agentGroupData);
                }
                if (!TextUtils.isEmpty(specificBean.getExpect_period())) {
                    AgentGroupData agentGroupData = new AgentGroupData("购车时间:", specificBean.getExpect_period());
                    agentGroupDatas.add(agentGroupData);
                }
                if (specificBean.getColors() != null && specificBean.getColors().size() > 0) {
                    AgentGroupData agentGroupData = new AgentGroupData("颜色:", getString(specificBean.getColors()));
                    agentGroupDatas.add(agentGroupData);
                }
                if (!TextUtils.isEmpty(specificBean.getAge_h())) {
                    AgentGroupData agentGroupData = new AgentGroupData("车龄:", specificBean.getAge_h() + "年");
                    agentGroupDatas.add(agentGroupData);
                }
                if (!TextUtils.isEmpty(specificBean.getMile_l()) && !TextUtils.isEmpty(specificBean.getMile_h())) {
                    AgentGroupData agentGroupData = new AgentGroupData("里程:", specificBean.getMile_l() + "-" + specificBean.getMile_h() + "万公里");
                    agentGroupDatas.add(agentGroupData);
                }else if(TextUtils.isEmpty(specificBean.getMile_l()) && !TextUtils.isEmpty(specificBean.getMile_h())) {
                    AgentGroupData agentGroupData = new AgentGroupData("里程:", specificBean.getMile_h() + "万公里以下");
                    agentGroupDatas.add(agentGroupData);
                }else if(!TextUtils.isEmpty(specificBean.getMile_l()) && TextUtils.isEmpty(specificBean.getMile_h())) {
                    AgentGroupData agentGroupData = new AgentGroupData("里程:", specificBean.getMile_l() +  "万公里以上");
                    agentGroupDatas.add(agentGroupData);
                }

            }
        }

        return agentGroupDatas;
    }


    private static String getString(List<String> datas) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < datas.size(); i++) {
            if (i == datas.size() - 1) {
                sb.append(datas.get(i));
            } else {
                sb.append(datas.get(i)).append(",");
            }
        }
        return sb.toString();
    }


    private static String getVehiclemodle(List<String> datas) {
        StringBuilder sb = new StringBuilder();
        int size = CarListFragment.need_carModel.length;
        for (int i = 0; i < datas.size(); i++) {
            for (int j = 0; j < size; j++) {
                if (CarListFragment.need_carModel[j].equals(datas.get(i))) {
                    if (i == datas.size() - 1) {
                        sb.append(CarListFragment.show_carModel[j]);
                    } else {
                        sb.append(CarListFragment.show_carModel[j]).append(",");
                    }
                }
            }

        }
        return sb.toString();
    }


}
